package ControlLayer;
import java.util.ArrayList;
import ModelLayer.*;
//model layer package has to be imported
/**
 * Controller class for the DVD collection
 * 
 * @author (kbh) 
 * @version (2005.03.31)
 * @revised version English (Ab)
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 * (KBH): 2010.04.09: Changed comments
 */
public class DVDCtr
{
    private DVDLager _dvdK;
    private DVD _d;
    private Copy _c;
  

    /**
     * Constructor for objects of class DVDCtr
     */
    public DVDCtr()
    {
        _dvdK = DVDLager.getInstance();
        _d = null;
        _c = null;
    }
    
    //Dummy implementation: after implementing the model layer 
    //objects of class DVD are to be returned, not String
    public String findDVD(long id)
    {
        //this method is to search the container for a DVD
        //with an id-number equal to the parameter no
        //when the dvd is found, the method is to call print-methods in the TUI layer
        _d = _dvdK.getDvd(id);
       
        String dvd = "ID: " +_d.getID() + "\n";
        dvd += "Title: " + _d.getTitle() + "\n";
        dvd += "Director: " + _d.getDirector() + "\n";
        dvd += "Release date: " + _d.getReleaseDate() + "\n";
        dvd += _d.listAllCopies();
       
        return dvd;
    }
    
    //Dummy implementation: more parameters are probaly to added
    public void createDVD(long id, String title, String director, String releaseDate)
    {       
          //this method constructs a new dvd object 
          //and stores it in the container
          _d = new DVD(id, title, director, releaseDate);
          _dvdK.addDVD(_d);
    }
    
    public void deleteDVD(long id)
    {
        
        //search for the dvd and delete the object from the container
       _dvdK.deleteDVD(id);
    }
    
    public void createCopy(long id, String serialNr, String obtainDate, String obtainPrice)
    {
        //create a copy of the specified dvd and add it to the dvd
        _d = _dvdK.getDvd(id);
        _c = new Copy(serialNr, obtainDate, obtainPrice);
        _d.addCopy(_c);
    }
    
    
    public String listAllDvds()
    {
          //returns a list of all dvds and their associated copies
          ArrayList<DVD> dvdD = _dvdK.listAllDvds();
          String dvds = "";
          
          for (DVD d : dvdD)
          {
              dvds += "ID: " + d.getID() + "\n";
              dvds += "Title: " + d.getTitle() + "\n";
              dvds += "Director: " + d.getDirector() + "\n";
              dvds += "Release date: " + d.getReleaseDate() + "\n";
              dvds += d.listAllCopies();
          }
          
          return dvds;
    }
}
